package com.molichuxing.services.infrastructure.service.impl;

import com.molichuxing.framework.dto.Paged;
import com.molichuxing.services.infrastructure.bean.MsgPushBean;
import com.molichuxing.services.infrastructure.convertor.Convert;
import com.molichuxing.services.infrastructure.dao.MsgPushMapper;
import com.molichuxing.services.infrastructure.dto.request.create.MsgPushCreateDto;
import com.molichuxing.services.infrastructure.dto.response.MsgPushDto;
import com.molichuxing.services.infrastructure.service.MsgPushService;
import com.molichuxing.services.property.MsgPushStatusEnum;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 消息推送 服务实现类
 * </p>
 *
 * @author 
 * @since 2019-08-14
 */
@Service("msgPushService")
public class MsgPushServiceImpl  implements MsgPushService {

  @Resource
  private MsgPushMapper msgPushMapper;

  @Override
  public MsgPushDto getMsgPushById(Integer id) {
    MsgPushBean msgPushBean = msgPushMapper.getById(id);
    return Convert.toMsgPushBeanDto(msgPushBean);
  }

  @Override
  public int createMsgPush(MsgPushCreateDto insertDto) {
    MsgPushBean msgPushBean = new MsgPushBean();
    BeanUtils.copyProperties(insertDto, msgPushBean);
    //false == 0   true ==1
    //todo  数据不完整
    return msgPushMapper.createMsgPushBean(msgPushBean);
  }

  @Override
  public Paged<MsgPushDto> getMsgPushListPage(String content, String sendOpName, MsgPushStatusEnum msgPushStatusEnum,
                                              LocalDateTime startSendTime, LocalDateTime endSendTime,
                                              Integer pageSize, Integer pageNum) {

    int count = msgPushMapper.getMsgPushPageCount(content,sendOpName,msgPushStatusEnum.getValue(),startSendTime,endSendTime);
    if(count <= 0) {
      return new Paged<>();
    }
    List<MsgPushBean> pageResult = msgPushMapper.getMsgPushPage(content,sendOpName,msgPushStatusEnum.getValue(),startSendTime,endSendTime, pageNum, pageSize);
    return new Paged<>(Convert.toMsgPushPageBeanDto(pageResult), count, pageSize );


  }

}
